package com.cms.tags;

/**
 * Title:        ECM
 * Description:
 * Copyright:    Copyright (c) 2003
 * Company:
 * @author
 * @version 4.0
 */

import java.io.*;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

import com.cms.config.Sorting;

public class SortColumnTag extends TagSupport {

	String sortCol;
	String name;
	String title;
	String caption;
	String sortDir;

	public void setSortCol(String sortCol) {
		this.sortCol = sortCol;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public void setSortDir(String sortDir) {
		this.sortDir = sortDir;
	}

	public int doStartTag() throws JspException {
		try {
			JspWriter out = pageContext.getOut();
			if (sortCol.equals(name)) {
				out.print("<th class=\"sel\"><nobr>");
				out.print("<a href=\"javascript:sortList('");
				out.print(name);
				out.print("')\" title = \"");
				out.print(title);
				out.print("\"><img src = ../img/common/");
				out.print(Sorting.getSortByImage(sortDir));
				out.print(" height=10 hspace=3 width=10 border=0>");
				out.print(caption);
				out.print("</a>&nbsp;</nobr></th>");
			} else {
				out.print("<th><nobr>");
				out.print("<a href=\"javascript:sortList('");
				out.print(name);
				out.print("')\" title = \"");
				out.print(title);
				out.print("\">");
				out.print(caption);
				out.print("</a>&nbsp;</nobr></th>");
			}

		} catch (IOException ioe) {
			throw new JspException("Error: IOException while writing to client"
					+ ioe.getMessage());
		}
		return SKIP_BODY;
	}

	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}
}
